package com.ruoyi.web.controller.firststage;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.firststage.domain.BrandCategory;
import com.ruoyi.firststage.domain.Product;
import com.ruoyi.firststage.service.IBrandCategoryService;
import com.ruoyi.firststage.service.IProductService;
import com.ruoyi.framework.util.ServletUtils;
import com.ruoyi.framework.web.page.PageDomain;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.page.TableSupport;
import com.ruoyi.web.core.base.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @创建人 cbx
 * @创建时间 2018/11/17 0017 下午 2:42
 * @描述    ean商品表
 */
@Controller
@RequestMapping("/firststage/product")
public class ProductController extends BaseController {
    private String prefix = "firststage/product";

    @Autowired
    private IProductService productService;
    @Autowired
    private IBrandCategoryService brandCategoryService;

    @RequiresPermissions("firststage:product:view")
    @GetMapping()
    public String user(ModelMap mmap)
    {
        List<String> brands = brandCategoryService.selectAllBrand();
        mmap.put("brands",brands);
        return prefix + "/list";
    }

    @RequiresPermissions("firststage:product:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo brandCategoryList(Product product)
    {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        if(pageDomain.getPageNum()==null&&pageDomain.getPageSize()==null){
            PageHelper.startPage(1, 500, "");
        }else{
            startPage();
        }
        List<Product> products = productService.selectProduct(product);
        return getDataTable(products);
    }


}
